credit2: Reset until the front of the runqueue is positive
authorGeorge Dunlap <george.dunlap@eu.citrix.com>
Mon, 11 Mar 2013 08:57:11 +0000 (09:57 +0100)
committerJan Beulich <jbeulich@suse.com>
Mon, 11 Mar 2013 08:57:11 +0000 (09:57 +0100)
commit4e98fd591232d33b1a3785fe1e5e1361955d9d90
tree43dd953fd16f3147ba0cc7eccbaddeae8cd30e62
parent582ea94410cb266bbf3cd308046f5ea8ae25055f
credit2: Reset until the front of the runqueue is positive

Under normal circumstances, snext->credit should never be less than
-CSCHED_MIN_TIMER.  However, under some circumstances, a vcpu with low
credits may be allowed to run long enough that its credits are
actually less than -CSCHED_CREDIT_INIT.

(Instances have been observed, for example, where a vcpu with 200us of
credit was allowed to run for 11ms, giving it -10.8ms of credit.  Thus
it was still negative even after the reset.)

If this is the case for snext, we simply want to keep moving everyone
up until it is in the black again.  This fair because none of the
other vcpus want to run at the moment.

Rather than loop, just detect how many times we want to add
CSCHED_CREDIT_INIT.  Try to avoid integer divides and multiplies in
the common case.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
xen/common/sched_credit2.c